package artid.com.arttogo.adapter;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import artid.com.arttogo.fragment.LotDetailFragment;

/**
 * ClassName:MatchFragmentAdapter <br/>
 * Function: 项目页适配器<br/>
 * Reason: 解决项目页标签可以左右滑动的功能 <br/>
 * Date: 2014-2-25 下午4:00:34 <br/>
 *
 * @author ybq
 * @see
 * @since JDK 1.6
 */
public class LotDetFragmentAdapter extends FragmentStatePagerAdapter {

    private ArrayList<String> mList;
    private List<LotDetailFragment> fragList;
    private ArrayList<String> mInsList = null;
    Boolean isFromOrgan = false;
    private String titileName;

    public LotDetFragmentAdapter(FragmentManager fm, String titileName) {
        super(fm);
        fragList = new ArrayList<LotDetailFragment>();
        this.titileName = titileName;
    }

    public void setData(ArrayList<String> list) {
        mList = list;
        notifyDataSetChanged();
    }

    public void setInsData(ArrayList<String> list) {
        mInsList = list;
        notifyDataSetChanged();
    }

    /**
     * 机构进入设置，与普通的详情不一样
     */
    public void setCodeMode(Boolean isFromOrgan) {
        this.isFromOrgan = isFromOrgan;
    }

    @Override
    public LotDetailFragment getItem(int position) {
        return getFragments(position);
    }

//	public ShareItem getShareitem(int position) {
//		return fragList.get(position).getShareitem();
//	}

//	
//	public String getTitle(int position) {
//		return fragList.get(position).getShareitem().getTitle();
//	}


    @Override
    public Object instantiateItem(ViewGroup group, int position) {
        return super.instantiateItem(group, position);
    }

    private LotDetailFragment getFragments(int position) {

        LotDetailFragment fragment = new LotDetailFragment(titileName);
        fragment.setArguments(getBundle(position));
        fragList.add(fragment);
        // return fragment;
        return fragment;
    }

    private Bundle getBundle(int position) {
        Bundle bundle = new Bundle();
        String id = "";
        if (mInsList != null) {
            id = mInsList.get(position);
            bundle.putString("id", id);
        } else {
            id = mList.get(position);
            bundle.putString("id", id);
        }


        bundle.putBoolean("isOrg", isFromOrgan);
        return bundle;
    }

    @Override
    public int getCount() {
        if (mInsList != null) {
            return mInsList.size();
        }
        return null == mList ? 0 : mList.size();
    }

    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }
}
